package me.helllp.dake.generator.utils;

import com.squareup.javapoet.TypeSpec;
import lombok.Getter;
import lombok.Setter;
import me.helllp.dake.generator.meta.core.*;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.lang.model.element.Modifier;
import java.util.List;

public class GenClassUtils {
    public static TypeSpec makeApplicationClass(String className) {
        SmartClass _class = new SmartClass();
        _class.setDesc("服务启动类");
        _class.setName(className);

        TypeSpec.Builder typeBuilder = _class.builder();

        return typeBuilder
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(new SmartAnnotation(new SmartType(SpringBootApplication.class), null).builder().build())
                .addMethod(GenMethodUtils.createMainMethod(className))
                .build();
    }

    public static TypeSpec makeBeanClass(String className, List<SmartField> fields) {
        SmartClass _class = new SmartClass();
        _class.setName(className);

        _class.setFields(fields);

        TypeSpec.Builder typeBuilder = _class.builder();

        return typeBuilder
                .addModifiers(Modifier.PUBLIC)
                .addAnnotation(Getter.class)
                .addAnnotation(Setter.class)
                .build();
    }
}
